<template>
	<view>
		<button @click="callStorageFun(1)" type="primary">setStorage</button>
		<button @click="callStorageFun(2)" type="primary">getStorage</button>
		<button @click="callStorageFun(3)" type="primary">removeStorage</button>
		<button @click="callStorageFun(4)" type="primary">getStorageInfo</button>
		<button @click="callStorageFun(5)" type="primary">clearStorage</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {}
		},
		methods: {
			callStorageFun(parm) {
				console.log("callStorageFun==>parm" + parm);
				switch (parm) {
					case 1:
						uni.setStorage({
							key: 'username',
							data: 'fqm',
							success: function(result) {
								console.log("UserName 成功", result);
							}
						});
						break;
					case 2:
						uni.getStorage({
							key: 'username', 
							success: function(result) {
								console.log("成功", result.data);
							},
							fail() {
								console.error("失败");
							}
						});
						break;
					case 3:
						uni.removeStorage({
							key: 'username', 
							success: function(res) {
								console.log("删除成功", res);
							}
						});
						break;
					case 4:
						uni.getStorageInfo({
							success: function(res) {
								console.log("keys:", res.keys);
								console.log("currentSize:", res.currentSize);
								console.log("limitSize:", res.limitSize);
							}
						});
						break;
					case 5:
						uni.clearStorage();
						break;
				}
			}
		}
	}
</script>

<style>
	button {
		margin: 30rpx;
		background-color: aqua;
	}
</style>